using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace WIT.DAQ.Core.Forms;

/// <summary>
/// SocketServer配置界面
/// </summary>
internal class SocketServerConfigForm : BaseForm
{
	/// <summary>
	///
	/// </summary>
	/// <param name="needLog">是否自动记录日志</param>
	/// <param name="nameSpace">命名空间</param>
	/// <param name="className">类名</param>
	/// <param name="methodName">方法名</param>
	/// <param name="identifier">消息标识</param>
	internal delegate void SaveSocketServerConfigHandler(bool needLog, string nameSpace, string className, string methodName, string identifier);

	/// <summary>
	/// Required designer variable.
	/// </summary>
	private IContainer components = null;

	private Button btnConfirm;

	private Button btnCancel;

	private GroupBox groupBox1;

	private TextBox txtMethodName;

	private Label label1;

	private TextBox txtClassName;

	private Label label2;

	private Label label3;

	private Label label4;

	private Label lblSocketServerPort;

	private CheckBox cbNeedLog;

	private TextBox txtIdentifier;

	private Label label5;

	private TextBox txtNamespace;

	private Label label7;

	private Label label6;

	/// <summary>
	///
	/// </summary>
	internal event SaveSocketServerConfigHandler SaveSocketServerConfig;

	/// <summary>
	///
	/// </summary> 
	internal SocketServerConfigForm()
	{
		InitializeComponent();
		cbNeedLog.Checked = Common.SocketServerNeedLog;
		txtNamespace.Text = Common.SocketServerNamespace;
		txtClassName.Text = Common.SocketServerClassName;
		txtMethodName.Text = Common.SocketServerMethodName;
		txtIdentifier.Text = Common.SocketServerMsgIdentifier;
	}

	private void SocketServerConfigForm_Load(object sender, EventArgs e)
	{
		lblSocketServerPort.Text = 10001.ToString();
	}

	private void btnConfirm_Click(object sender, EventArgs e)
	{
		bool @checked = cbNeedLog.Checked;
		string nameSpace = txtNamespace.Text.Trim();
		string className = txtClassName.Text.Trim();
		string methodName = txtMethodName.Text.Trim();
		string identifier = txtIdentifier.Text.Trim();
		this.SaveSocketServerConfig(@checked, nameSpace, className, methodName, identifier);
		Close();
	}

	private void btnCancel_Click(object sender, EventArgs e)
	{
		Close();
	}

	private void SocketServerConfigForm_KeyDown(object sender, KeyEventArgs e)
	{
		if (e.KeyCode == Keys.Escape)
		{
			btnCancel_Click(null, null);
		}
	}

	/// <summary>
	/// Clean up any resources being used.
	/// </summary>
	/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
	protected override void Dispose(bool disposing)
	{
		if (disposing && components != null)
		{
			components.Dispose();
		}
		base.Dispose(disposing);
	}

	/// <summary>
	/// Required method for Designer support - do not modify
	/// the contents of this method with the code editor.
	/// </summary>
	private void InitializeComponent()
	{
		this.btnConfirm = new System.Windows.Forms.Button();
		this.btnCancel = new System.Windows.Forms.Button();
		this.groupBox1 = new System.Windows.Forms.GroupBox();
		this.cbNeedLog = new System.Windows.Forms.CheckBox();
		this.txtMethodName = new System.Windows.Forms.TextBox();
		this.label1 = new System.Windows.Forms.Label();
		this.txtIdentifier = new System.Windows.Forms.TextBox();
		this.txtClassName = new System.Windows.Forms.TextBox();
		this.label5 = new System.Windows.Forms.Label();
		this.label2 = new System.Windows.Forms.Label();
		this.label3 = new System.Windows.Forms.Label();
		this.label4 = new System.Windows.Forms.Label();
		this.lblSocketServerPort = new System.Windows.Forms.Label();
		this.label6 = new System.Windows.Forms.Label();
		this.label7 = new System.Windows.Forms.Label();
		this.txtNamespace = new System.Windows.Forms.TextBox();
		this.groupBox1.SuspendLayout();
		base.SuspendLayout();
		this.btnConfirm.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right;
		this.btnConfirm.Location = new System.Drawing.Point(266, 239);
		this.btnConfirm.Name = "btnConfirm";
		this.btnConfirm.Size = new System.Drawing.Size(75, 23);
		this.btnConfirm.TabIndex = 2;
		this.btnConfirm.Text = "确认(&S)";
		this.btnConfirm.UseVisualStyleBackColor = true;
		this.btnConfirm.Click += new System.EventHandler(btnConfirm_Click);
		this.btnCancel.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right;
		this.btnCancel.Location = new System.Drawing.Point(347, 239);
		this.btnCancel.Name = "btnCancel";
		this.btnCancel.Size = new System.Drawing.Size(75, 23);
		this.btnCancel.TabIndex = 3;
		this.btnCancel.Text = "取消(&C)";
		this.btnCancel.UseVisualStyleBackColor = true;
		this.btnCancel.Click += new System.EventHandler(btnCancel_Click);
		this.groupBox1.Controls.Add(this.cbNeedLog);
		this.groupBox1.Controls.Add(this.txtMethodName);
		this.groupBox1.Controls.Add(this.label1);
		this.groupBox1.Controls.Add(this.txtIdentifier);
		this.groupBox1.Controls.Add(this.txtNamespace);
		this.groupBox1.Controls.Add(this.txtClassName);
		this.groupBox1.Controls.Add(this.label7);
		this.groupBox1.Controls.Add(this.label5);
		this.groupBox1.Controls.Add(this.label6);
		this.groupBox1.Controls.Add(this.label2);
		this.groupBox1.Controls.Add(this.label3);
		this.groupBox1.Location = new System.Drawing.Point(12, 55);
		this.groupBox1.Name = "groupBox1";
		this.groupBox1.Size = new System.Drawing.Size(410, 172);
		this.groupBox1.TabIndex = 1;
		this.groupBox1.TabStop = false;
		this.groupBox1.Text = "接收到客户端数据后";
		this.cbNeedLog.AutoSize = true;
		this.cbNeedLog.Checked = true;
		this.cbNeedLog.CheckState = System.Windows.Forms.CheckState.Checked;
		this.cbNeedLog.Location = new System.Drawing.Point(91, 31);
		this.cbNeedLog.Name = "cbNeedLog";
		this.cbNeedLog.Size = new System.Drawing.Size(72, 16);
		this.cbNeedLog.TabIndex = 0;
		this.cbNeedLog.Text = "自动日志";
		this.cbNeedLog.UseVisualStyleBackColor = true;
		this.txtMethodName.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
		this.txtMethodName.Location = new System.Drawing.Point(91, 107);
		this.txtMethodName.Name = "txtMethodName";
		this.txtMethodName.Size = new System.Drawing.Size(294, 21);
		this.txtMethodName.TabIndex = 3;
		this.label1.AutoSize = true;
		this.label1.Location = new System.Drawing.Point(20, 110);
		this.label1.Name = "label1";
		this.label1.Size = new System.Drawing.Size(65, 12);
		this.label1.TabIndex = 12;
		this.label1.Text = "执行方法：";
		this.txtIdentifier.Location = new System.Drawing.Point(91, 134);
		this.txtIdentifier.Name = "txtIdentifier";
		this.txtIdentifier.Size = new System.Drawing.Size(150, 21);
		this.txtIdentifier.TabIndex = 4;
		this.txtClassName.Location = new System.Drawing.Point(91, 80);
		this.txtClassName.Name = "txtClassName";
		this.txtClassName.Size = new System.Drawing.Size(150, 21);
		this.txtClassName.TabIndex = 2;
		this.label5.AutoSize = true;
		this.label5.Location = new System.Drawing.Point(20, 137);
		this.label5.Name = "label5";
		this.label5.Size = new System.Drawing.Size(65, 12);
		this.label5.TabIndex = 12;
		this.label5.Text = "消息标识：";
		this.label2.AutoSize = true;
		this.label2.ForeColor = System.Drawing.SystemColors.ControlDark;
		this.label2.Location = new System.Drawing.Point(247, 83);
		this.label2.Name = "label2";
		this.label2.Size = new System.Drawing.Size(65, 12);
		this.label2.TabIndex = 12;
		this.label2.Text = "可指定类名";
		this.label3.AutoSize = true;
		this.label3.Location = new System.Drawing.Point(20, 83);
		this.label3.Name = "label3";
		this.label3.Size = new System.Drawing.Size(65, 12);
		this.label3.TabIndex = 12;
		this.label3.Text = "类    名：";
		this.label4.AutoSize = true;
		this.label4.Location = new System.Drawing.Point(32, 23);
		this.label4.Name = "label4";
		this.label4.Size = new System.Drawing.Size(65, 12);
		this.label4.TabIndex = 21;
		this.label4.Text = "端    口：";
		this.lblSocketServerPort.AutoSize = true;
		this.lblSocketServerPort.Location = new System.Drawing.Point(101, 23);
		this.lblSocketServerPort.Name = "lblSocketServerPort";
		this.lblSocketServerPort.Size = new System.Drawing.Size(29, 12);
		this.lblSocketServerPort.TabIndex = 0;
		this.lblSocketServerPort.Text = "port";
		this.label6.AutoSize = true;
		this.label6.Location = new System.Drawing.Point(20, 56);
		this.label6.Name = "label6";
		this.label6.Size = new System.Drawing.Size(65, 12);
		this.label6.TabIndex = 12;
		this.label6.Text = "命名空间：";
		this.label7.AutoSize = true;
		this.label7.ForeColor = System.Drawing.SystemColors.ControlDark;
		this.label7.Location = new System.Drawing.Point(247, 56);
		this.label7.Name = "label7";
		this.label7.Size = new System.Drawing.Size(89, 12);
		this.label7.TabIndex = 12;
		this.label7.Text = "可指定命名空间";
		this.txtNamespace.Location = new System.Drawing.Point(91, 53);
		this.txtNamespace.Name = "txtNamespace";
		this.txtNamespace.Size = new System.Drawing.Size(150, 21);
		this.txtNamespace.TabIndex = 1;
		base.AutoScaleDimensions = new System.Drawing.SizeF(6f, 12f);
		base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
		base.ClientSize = new System.Drawing.Size(434, 274);
		base.Controls.Add(this.lblSocketServerPort);
		base.Controls.Add(this.label4);
		base.Controls.Add(this.groupBox1);
		base.Controls.Add(this.btnConfirm);
		base.Controls.Add(this.btnCancel);
		base.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
		base.MaximizeBox = false;
		base.Name = "SocketServerConfigForm";
		this.Text = "Socket服务配置";
		base.Load += new System.EventHandler(SocketServerConfigForm_Load);
		base.KeyDown += new System.Windows.Forms.KeyEventHandler(SocketServerConfigForm_KeyDown);
		this.groupBox1.ResumeLayout(false);
		this.groupBox1.PerformLayout();
		base.ResumeLayout(false);
		base.PerformLayout();
	}
}
